<?php

namespace App\Models;
use Illuminate\Contracts\Auth\Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class Admins extends BaseModel implements JWTSubject, Authenticatable
{
    protected $table = 'admins';
    
    // 用户状态常量
    const STATUS_DISABLED = 0;  // 禁用状态
    const STATUS_ENABLED = 1;   // 启用状态

    protected $hidden = ['password'];
    
    /**
     * 重写查询构造方法
     * @param array $params 查询参数
     * @return \Illuminate\Database\Eloquent\Builder
     */
    protected function buildQuery(array $params = []): \Illuminate\Database\Eloquent\Builder
    {
        $query = parent::buildQuery($params);

        if (!empty($params['start_time'])) {
            $query->where('created_at', '>=', strtotime($params['start_time']));
        }
        if (!empty($params['end_time'])) {
            $endTime = strtotime($params['end_time']) + 86400 - 1;
            $query->where('created_at', '<=', $endTime);
        }
        return $query;
    }

    /**
     * 获取表字段
     * @return array
     */
    protected function columns(): array
    {
        return [
            'id',
            'username',
            'email',
            'password',
            'name',
            'avatar',
            'status',
            'created_at',
            'updated_at',
            'deleted_at'
        ];
    }

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims(): array
    {
        return [];
    }

    /**
     * Get the name of the unique identifier for the user.
     * @return string
     */
    public function getAuthIdentifierName(): string
    {
        return 'id';
    }

    /**
     * Get the unique identifier for the user.
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->id;
    }

    /**
     * Get the password for the user.
     * @return string
     */
    public function getAuthPassword(): string
    {
        return $this->password;
    }

    /**
     * Get the token value for the "remember me" session.
     * @return string|null
     */
    public function getRememberToken(): ?string
    {
        return null;
    }

    /**
     * Set the token value for the "remember me" session.
     * @param string $value
     * @return void
     */
    public function setRememberToken($value): void
    {
    }

    /**
     * Get the column name for the "remember me" token.
     * @return string
     */
    public function getRememberTokenName(): string
    {
        return '';
    }
}